package com.nowoe.data.sqlSession;

import com.nowoe.data.config.Configuration;
import com.nowoe.data.parse.XMLConfigBuilder;
import org.dom4j.DocumentException;

import java.io.InputStream;

/**
 * @author 倚栏听风 2023/9/14 15:37
 */
public class SqlSessionFactoryBuilder {
    /**
     * 解析配置文件SqlSessionFactory
     *
     * @return SqlSessionFactory
     */
    public SqlSessionFactory build(InputStream inputStream) throws DocumentException {
        //解析文件到Configuration
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parse(inputStream);

        //创建SqlSessionFactory工厂
        return new DefaultSqlSessionFactory(configuration);
    }
}
